//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Research.DataLayer
{
    /// <summary>
    /// Generic exception that represents failure to communicate with the storage
    /// backend.
    /// </summary>
    public class BackendStorageException : Exception
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public BackendStorageException(string msg, Exception inner)
            : base(msg, inner)
        {
        }
    }

    /// <summary>
    /// Generic exception that represents failure of an action requested to the
    /// storage backend
    /// </summary>
    public class DataAccessException : Exception
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public DataAccessException(string msg, Exception inner)
            : base(msg, inner)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        public DataAccessException(string msg)
            : base(msg)
        {
        }
    }

    /// <summary>
    /// Connection to the data backend failed
    /// </summary>
    public class ConnectionFailure : BackendStorageException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public ConnectionFailure(string msg, Exception inner)
            : base(msg, inner)
        {
        }
    }

    /// <summary>
    /// Object is in use by another object (and can't be deleted)
    /// </summary>
    public class ObjectInUseException : DataAccessException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public ObjectInUseException(string msg, Exception inner)
            : base(msg, inner)
        {
        }
    }

    /// <summary>
    /// Object already exists in the backend (and cannot be added)
    /// </summary>
    public class ObjectAlreadyExists : DataAccessException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public ObjectAlreadyExists(string msg, Exception inner)
            : base(msg, inner)
        {
        }
    }

    /// <summary>
    /// Relationship between objects already present in the backend
    /// (and cannot be added)
    /// </summary>
    public class RelationshipAlreadyExists : DataAccessException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="inner"></param>
        public RelationshipAlreadyExists(string msg, Exception inner)
            : base(msg, inner)
        {
        }
    }
    
    /// <summary>
    /// Object not found in the storage backend
    /// </summary>
    public class RecordNotFoundException : DataAccessException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        public RecordNotFoundException(string msg)
            : base(msg)
        {
        }
    }

    /// <summary>
    /// Incorrect Binding of versions.
    /// </summary>
    public class BindVersionViolation : Exception
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        public BindVersionViolation(string msg)
            : base(msg)
        {
        }
    }

    /// <summary>
    /// Policy mismatch exception.
    /// </summary>
    public class PolicyMismatchException : Exception
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        public PolicyMismatchException(string msg)
            : base(msg)
        {
        }
    }

    /// <summary>
    /// Not Authenticated Exception
    /// </summary>
    public class NotAuthenticatedException : System.Security.SecurityException
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="msg"></param>
        public NotAuthenticatedException(string msg)
            : base(msg)
        {
        }
    }
}
